﻿using System;
using System.Reflection;
using Microsoft.FxCop.Sdk;

namespace Community.StaticAnalysis.Design.Rules
{
    /// <summary>
    /// The <see cref="CheckPropertyRule"/>
    /// class is used to facilitate the checking of property members in a type.
    /// </summary>
    internal abstract class CheckPropertyRule : BaseIntrospectionRule
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="CheckPropertyRule"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="resourceName">Name of the resource.</param>
        /// <param name="resourceAssembly">The resource assembly.</param>
        protected CheckPropertyRule(String name, String resourceName, Assembly resourceAssembly)
            : base(name, resourceName, resourceAssembly)
        {
        }

        /// <summary>
        /// Checks the specified member.
        /// </summary>
        /// <param name="member">The member.</param>
        /// <returns></returns>
        public override ProblemCollection Check(Member member)
        {
            PropertyNode property = member as PropertyNode;

            // Check if the member is a property
            if (property == null)
            {
                return null;
            }

            Check(property);

            return Problems;
        }

        /// <summary>
        /// Checks the specified property.
        /// </summary>
        /// <param name="property">The property.</param>
        public abstract void Check(PropertyNode property);
    }
}